<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 积分兑换
 * @package  htdocs
 * @subpackage  quanliadmin
 * @create by allen.qiang
 */


class pa_pointsConvert {

    public function execute() {
        global $G_PGLOB ;
        if (isset($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1: //积分兑换列表
                    $this->pointsConvertList();
                    break;

                case 2: //添加积分兑换
                    $this->pointsConvertAdd();
                    break;

                case 3: //编辑积分兑换
                    $this->pointsConvertEdit();
                    break;

                default:
                    $G_PGLOB->smarty->assign('msg', '参数错误，请审核后再操作');
                    $G_PGLOB->smarty->display('comm/error.tpl');

            }
        }
    }

    /**
     * 积分兑换列表
     *
     */
    private function pointsConvertList() {

        global $G_PGLOB;

        //帐户礼品券
        $accountCoupon = $G_PGLOB->DBCA->stmt_query('SELECT couponID,couponName FROM promotion_coupon WHERE couponType=2 AND startDate<=? AND endDate>=?' ,'ss' , $G_PGLOB->sys_datetime,$G_PGLOB->sys_datetime);

        $G_PGLOB->smarty->assign('accountCoupon' , $accountCoupon);

        $G_PGLOB->smarty->display('promotion/pointsConvertList.tpl');

    }

    /**
     * 添加积分兑换
     */
    private function pointsConvertAdd () {

        global $G_PGLOB;

        //帐户礼品券
        $accountCoupon = $G_PGLOB->DBCA->stmt_query('SELECT couponID,couponName FROM promotion_coupon WHERE couponType=2 AND startDate<=? AND endDate>=?' ,'ss' , $G_PGLOB->sys_datetime,$G_PGLOB->sys_datetime);

        $G_PGLOB->smarty->assign('accountCoupon' , $accountCoupon);
        $G_PGLOB->smarty->assign('operFlg', 2);
        $G_PGLOB->smarty->display('promotion/pointsConvertAdd.tpl');

    }

    /**
     * 编辑积分兑换
     */
    public function pointsConvertEdit() {

        global $G_PGLOB;

        if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
            $G_PGLOB->smarty->assign('msg', '参数错误');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;

        }

        //查询客户信息
        $pointsConvert_obj = new entity('promotion_points_coupon');
        $pointsConvert_obj->promotionID = $_REQUEST['id'];

        if( !$G_PGLOB->DBCA->fetch($pointsConvert_obj) ){
            $G_PGLOB->smarty->assign('msg', '没有找到信息');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;
        }

        //帐户礼品券
        $accountCoupon = $G_PGLOB->DBCA->stmt_query('SELECT couponID,couponName FROM promotion_coupon WHERE couponType=2 AND startDate<=? AND endDate>=?' ,'ss' , $G_PGLOB->sys_datetime,$G_PGLOB->sys_datetime);

        $G_PGLOB->smarty->assign('accountCoupon' , $accountCoupon);
        $G_PGLOB->smarty->assign('pointsConvertInfo' , $pointsConvert_obj);
        $G_PGLOB->smarty->assign('operFlg', 3);
        $G_PGLOB->smarty->display('promotion/pointsConvertAdd.tpl');

    }

}